<?php

namespace Mlym\CodeGeneration\ControllerGeneration;


use Mlym\CodeGeneration\ClassGeneration\ClassGeneration;
use Mlym\CodeGeneration\ClassGeneration\MethodAbstract;
use Mlym\CodeGeneration\ControllerGeneration\Method\Add;
use Mlym\CodeGeneration\ControllerGeneration\Method\Del;
use Mlym\CodeGeneration\ControllerGeneration\Method\GetByWhere;
use Mlym\CodeGeneration\ControllerGeneration\Method\GetList;
use Mlym\CodeGeneration\ControllerGeneration\Method\GetSelectPage;
use Mlym\CodeGeneration\ControllerGeneration\Method\Info;
use Mlym\CodeGeneration\ControllerGeneration\Method\Edit;
use EasySwoole\Component\Context\ContextManager;
use EasySwoole\Http\Message\Status;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiFail;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroup;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroupAuth;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroupDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiRequestExample;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccess;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccessParam;
use EasySwoole\HttpAnnotation\AnnotationTag\InjectParamsContext;
use EasySwoole\HttpAnnotation\AnnotationTag\Method;
use EasySwoole\HttpAnnotation\AnnotationTag\Param;
use EasySwoole\Validate\Validate;
use Nette\PhpGenerator\PhpNamespace;
use Throwable;

class ControllerGeneration extends ClassGeneration
{
    /**
     * @var $config ControllerConfig
     */
    protected $config;


    function addClassData()
    {
        $this->addUse($this->phpNamespace);
        $this->addGenerationMethod(new Add($this));
        $this->addGenerationMethod(new Edit($this));
        $this->addGenerationMethod(new Info($this));
        $this->addGenerationMethod(new GetByWhere($this));
        $this->addGenerationMethod(new GetSelectPage($this));
        $this->addGenerationMethod(new GetList($this));
        $this->addGenerationMethod(new Del($this));
    }

    function getClassName()
    {
        return $this->config->getRealTableName() . $this->config->getFileSuffix();
    }

    protected function addUse(PhpNamespace $phpNamespace)
    {
        $phpNamespace->addUse($this->config->getModelClass());
        $phpNamespace->addUse(Status::class);
        $phpNamespace->addUse(Validate::class);
        $phpNamespace->addUse(Validate::class);
        $phpNamespace->addUse($this->config->getExtendClass());
        //引入新版注解,以及文档生成
        $phpNamespace->addUse(ApiGroup::class);
        $phpNamespace->addUse(ApiGroupAuth::class);
        $phpNamespace->addUse(ApiGroupDescription::class);
        $phpNamespace->addUse(ApiFail::class);
        $phpNamespace->addUse(ApiRequestExample::class);
        $phpNamespace->addUse(ApiSuccess::class);
        $phpNamespace->addUse(Method::class);
        $phpNamespace->addUse(Param::class);
        $phpNamespace->addUse(Api::class);
        $phpNamespace->addUse(ApiSuccessParam::class);
        $phpNamespace->addUse(ApiDescription::class);
        $phpNamespace->addUse(ContextManager::class);
        $phpNamespace->addUse(InjectParamsContext::class);
        $phpNamespace->addUse(Throwable::class);
    }

    function addGenerationMethod(MethodAbstract $abstract)
    {
        $this->methodGenerationList[$abstract->getMethodName()] = $abstract;
    }

    function addComment()
    {
        parent::addComment();
    }
}
